﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Report._1._HocVien;
using CoreData;
using SchoolManagementSystem.Controls;
using DevExpress.XtraEditors.Controls;
namespace SchoolManagementSystem.Forms.BusinessForm
{
    public partial class frmReportTempStudent : DevExpress.XtraEditors.XtraForm
    {
        public frmReportTempStudent()
        {
            InitializeComponent();
            
            SetDefault();

        }

        void SetDefault()
        {
          
            dateEdit_from.DateTime = DateTime.Now.AddMonths(-6);
            dateEdit_to.DateTime = DateTime.Now;
          
        }


        string BranchiD;
        long StatusiD;
        long ChaneliD;

       
        void ShowReport()
        {
            DanhSachTheoNhiuTieuChi();
        }

  

        private void simpleButton_View_Click(object sender, EventArgs e)
        {
            ShowReport();
        }

       

        void DanhSachTheoNhiuTieuChi()
        {

            string search = "";
            if(StatusiD!=0)
            {
                search += "TempStudent.Status =" + StatusiD +" and";
            }
            if(ChaneliD!=0)
            {
                search += "TempStudent.ChannelInfoID =" + ChaneliD +" and";
            }
            if(!String.IsNullOrEmpty(BranchiD))
            {
                search += "TempStudent.BranchID like N'%" + BranchiD+"%' and";
            }

            search += " Convert(varchar(11), TempStudent.ContactDate, 120) BETWEEN '" + dateEdit_from.DateTime.ToString("yyyy-MM-dd") + "' and '" + dateEdit_to.DateTime.ToString("yyyy-MM-dd") + "'";
            DanhSachHocVienTiemNang ds = new DanhSachHocVienTiemNang();
            var data = HocVienReportData.LoadTempStudentByMultiCondition(search);
            ds.from = dateEdit_from.DateTime;
            ds.to = dateEdit_to.DateTime;
            ds.DataSource = data;
            printControl1.PrintingSystem = ds.PrintingSystem;
            ds.CreateDocument();

        }

     

       
        private void radioGroup1_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }

      

        private void buttonEdit_Branch_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 0)
            {
                frmMultiSelectBranch select = new frmMultiSelectBranch("");
                if (select.ShowDialog() == DialogResult.OK)
                {
                    string data = select.SelectName();
                    buttonEdit_Branch.EditValue = data;
                    BranchiD = data;
                }
                else
                {
                    buttonEdit_Branch.EditValue = "";
                    BranchiD = "";
                }
            }
        }

        private void buttonEdit_Status_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 0)
            {
                frmSelectStatus select = new frmSelectStatus(2);
                if (select.ShowDialog() == DialogResult.OK)
                {
                    string data = "[" + select.Code + "] " + select.Name;
                    buttonEdit_Status.EditValue = data;
                    StatusiD = select.ID;
                }
                else
                {
                    buttonEdit_Status.EditValue = ""; StatusiD = 0;
                }
            }
        }

        private void buttonEdit_Channel_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 0)
            {
                frmSelectChannel select = new frmSelectChannel();
                if (select.ShowDialog() == DialogResult.OK)
                {
                    string data = "[" + select.Code + "] " + select.Name;
                    buttonEdit_Channel.EditValue = data;
                    ChaneliD = select.ID;
                }
                else
                {
                    buttonEdit_Channel.EditValue = ""; ChaneliD = 0;
                }
            }
        }

      

    }
}
